package com.ywl.designpattern.responsibility;

/**
 * 1.首先，创建一个抽象的日志处理者类
 * @author yuwl
 * @description
 * @since 2024-06-28 09:50
 */
public abstract class LogHandler {

    protected LogHandler nextHandler;
    protected int level;

    // 级别
    public static final int INFO = 1;
    public static final int DEBUG = 2;
    public static final int ERROR = 3;

    public void setNextHandler(LogHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    public void logMessage(int level, String message) {
        if (this.level <= level) {
            write(message);
        }
        if (nextHandler != null) {
            nextHandler.logMessage(level, message);
        }
    }

    abstract protected void write(String message);
}
